#include "card.h"

int Card::getId() const
{
    return id;
}

QString Card::getUsername() const
{
    return username;
}

QString Card::getUserPic() const
{
    return userPic;
}

int Card::getLeaveTime() const
{
    return leaveTime;
}

void Card::setLeaveTime(int current)
{
    leaveTime = current + qrand() % 300;
}

bool Card::compLeaveTime(Card a, Card b)
{
    return a.getLeaveTime() > b.getLeaveTime();
}

Card::Card()
{
    id       = 0;
    username = "Mr.Nobody";
    cardNum  = "000000";
    userPic  = ":/img/nobody.png";
    status   = false;
    taken    = -1;
}

Card::Card(QString cardNum)
{
    this->cardNum = cardNum;
}

Card::Card(int i, QString num,QString name, QString pic, int t, bool s){
    id = i;
    cardNum = num;
    username = name;
    userPic = pic;
    taken = t;
    status = s;
}

QString Card::getCardNum()
{
    return cardNum;
}

bool Card::getStatus()
{
    return status;
}

void Card::setStatus(bool status)
{
    this->status = status;
}

int Card::getTaken()
{
    return taken;
}

void Card::setTaken(int taken)
{
    this->taken = taken;
}

Card *Card::randomGenerate()
{
    int randNum = qrand() % 99;
    QString randomNum;
    if(randNum < 10){
        randomNum = QString("00000%1").arg(randNum);
    }else{
        randomNum = QString("0000%1").arg(randNum);
    }
    return new Card(randomNum);
}

void Card::setCardNum(QString cardNum)
{
    this->cardNum = cardNum;
}

Card Card::operator=(Card card){

    Card newCard = Card();

    newCard.cardNum = card.getCardNum();
    newCard.status  = card.getStatus();
    newCard.taken   = card.getTaken();

    return newCard;
}
